package com.trump.baiduim.netty.config;

import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;


import java.util.concurrent.ConcurrentHashMap;

/**
 * @author guoyuans
 */
@Slf4j
public class UserChannel {
    /**
     * 通过用户account与channel绑定
     */
    private static ConcurrentHashMap<String, Channel> manager = new ConcurrentHashMap<>();

    /**
     * 用户account与channel绑定
     * @param userAccount
     * @param channel
     */
    public static void put(String userAccount,Channel channel) {
        manager.put(userAccount,channel);
    }
    
    public static Channel get(String userAccount) {
        return manager.get(userAccount);
    }

    /**
     * 判断用户是否在线
     * @param userAccount
     * @return
     */
    public static boolean isContainKey(String userAccount) {
        return manager.containsKey(userAccount);
    }
    
    public static void output() {
        for (String key:manager.keySet()) {
            log.info("userAccount:"+key+",ChannelId:"+manager.get(key));
        }
    }
}
